package neuronet.client;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.MalformedURLException;
import java.net.Socket;
import java.net.URL;
import java.util.Random;
import java.util.Vector;

import neuronet.client.gui.ClientFrame;
import neuronet.common.NeuroNetCom;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;

public class NeuroNetClient {

    private static final boolean GLOBALSOCKET = false;

    // Logger
    private static Logger logger = Logger.getLogger(NeuroNetClient.class);

    // IO-Streams
    ObjectInputStream inputStream;
    ObjectOutputStream outputStream;

    // The client socket
    Socket socket;

    // severIP
    private static String serverURL = "141.2.158.90";
    //    private static String serverURL = "192.168.178.22";
    private static int serverPort = 1504;

    // clientdata
    private String clientID = "";
    private String clientinfo = "";
    private String clientkey = "";

    // GUI
    private static ClientFrame gui;

    ClientMessageThread t;

    // TODO: Replace consistend "messages" with "data"

    /**
     * Constructor 
     * 
     * @param serverURL 	server URL
     * @param serverPort 	port for communication with server
     */
    public NeuroNetClient(String serverURL, int serverPort)
    {
	Random r = new Random();

	setClientID("baumstamm" + r.nextInt(5000));

	NeuroNetClient.serverPort = serverPort;
	NeuroNetClient.serverURL = serverURL;
	setClientInfo("Pappelbieger_Testaufwand_Extruder");

	initClient();
	doSomething();
    }

    /**
     * Constructor 
     * 
     * @param serverURL 	server URL
     * @param serverPort 	port for communication with server
     * @param clientid 		name of new client
     */
    public NeuroNetClient(String serverURL, int serverPort, String clientid)
    {
	this.setClientID(clientid);

	NeuroNetClient.serverPort = serverPort;
	NeuroNetClient.serverURL = serverURL;
	setClientInfo("Pappelbieger_Testaufwand_Extruder");

	// init client 
	initClient();

	//	// do something useful
	//	doSomething();
    }

    /**
     * Method creates Thread which looks for new messages
     * 
     */
    private void createMessageThread()
    {
	logger.info("  [[[* *+++* ]]]  ");
	logger.info("Creating client message thread for client " + getClientID());
	//	ClientMessageThread t = new ClientMessageThread(serverURL, serverPort, clientid); 
	t = new ClientMessageThread(this);
	logger.info("Starting message thread");
	logger.info("  [[[* *+++* ]]]  ");
    }

    /**
     * Method starts previous created thread which looks for new messages
     * 
     */
    private void startMessageThread()
    {
	t.setClientkey(getClientKey());
	t.start();

    }

    /**
     * Method for initialization of client.
     */
    private void initClient()
    {
	//	gui = new ClientFrame();
	initGUI();

	if (GLOBALSOCKET)
	{

	    try
	    {
		logger.info(" Trying to connect to server " + serverURL + " on port " + serverPort);
		socket = new Socket(serverURL, serverPort);
	    }
	    catch (Exception e)
	    {
		logger.error("Error connectiong to server:", e);
		return;
	    }
	    logger.info("Connection accepted " + socket.getInetAddress() + ":" + socket.getPort());
	    // connection established
	}

    }

    /**
     * This method creates the GUI
     */
    private void initGUI()
    {
	//	SwingUtilities.invokeLater(new Runnable()
	//	{
	//
	//	    public void run()
	//	    {
	setGUI(new ClientFrame(this));
	//		gui.setLocationRelativeTo(null);
	getGUI().setLocation(470, 0);
	getGUI().setClientID(clientID);
	getGUI().setServerURL(serverURL);
	getGUI().setServerPort(serverPort);
	getGUI().setDataItems("x1,xx2,Time,Out,OP1");
	getGUI().setTargets("Client0001,Client0002");
	getGUI().setVisible(true);
	//	    }
	//	});

    }

    /**
     * Method which produces network traffic.
     */
    private void doSomething()
    {
	resetServer();
	//	logger.debug("#################################################");
	//	logonClient();

	logger.debug("#################################################");
	configureClient(getGUI().getDataItems(), getGUI().getTargets());
	logger.debug("#################################################");
	getClients();
	logger.debug("#################################################");
	sendDummyData();
	logger.debug("#################################################");
	sendDummyData();
	logger.debug("#################################################");
	sendDummyData();
	logger.debug("#################################################");
	sendDummyData();
	//	logger.debug("#################################################");
	//	getData();
	//	logger.debug("#################################################");
	//	logoffClient();

	// create start thread for pulling of messages
	createMessageThread();
	startMessageThread();

    }

    //    public NeuroNetClient(String serverURL, int serverPort, String clientid)
    //    {
    //	clientinfo = "Pappelbieger_Testaufwand_Extruder";
    //
    //	//	// Creating data streams
    //	//	try
    //	//	{
    //	//	    inputStream = new ObjectInputStream(socket.getInputStream());
    //	//	    outputStream = new ObjectOutputStream(socket.getOutputStream());
    //	//	}
    //	//	catch (IOException e)
    //	//	{
    //	//	    logger.error("Exception creating new Input/output Streams: ", e);
    //	//	    return;
    //	//	}
    //
    //
    //	//	String test = "type:logon clientid:baum clientinfo:Pasdaschleuder end:end";
    //	//	// send the string to the server
    //	//	logger.info("Client sending \"" + test + "\" to serveur");
    //	//	try
    //	//	{
    //	//	    outputStream.writeObject(test);
    //	//	    outputStream.flush();
    //	//	}
    //	//	catch (IOException e)
    //	//	{
    //	//	    logger.error("Error writting to the socket: ", e);
    //	//	    return;
    //	//	}
    //	//	// read server answer
    //	//	String response;
    //	//	try
    //	//	{
    //	//	    response = (String) inputStream.readObject();
    //	//	    logger.info("Read from server: " + response);
    //	//	}
    //	//	catch (Exception e)
    //	//	{
    //	//	    logger.error("Problem while reading from server: ", e);
    //	//	}
    //
    //	//	// close connections
    //	//	finally
    //	//	{
    //	//		    try
    //	//		    {
    //	//			inputStream.close();
    //	//			outputStream.close();
    //	//		    }
    //	//		    catch (Exception e)
    //	//		    {
    //	//			logger.error("Problem while closing connection: ", e);
    //	//		    }
    //	//	}
    //    }

    /**
     * This method request the list of targets registered for the client
     * 
     */
    private String getTargets(String requestClientID)
    {
	String send = "type:gettargets clientid:" + getClientID() + " clientkey:" + getClientKey() + " requestclientid:" + requestClientID + " end:end";
	String mess = sendDataString(send);
	logger.info("sendDataString in getTargets() returned = " + mess);

	//	Vector<String> dataVec = NeuroNetCom.extractDataFromMessage(mess, "targets");
	String dataString = NeuroNetCom.getParameterFormMessage("targets", mess);

	return dataString;
    }

    /**
     * This method requests list of targets for the specified client from server.
     * @return StringVector as list of targets
     */
    public Vector<String> getTargetsAsVector(String requestClientID)
    {
	String targets = getTargets(requestClientID);

	Vector<String> dataVec = NeuroNetCom.getStringAsVector(targets, ",");
	return dataVec;
    }

    /**
     * This method requests list of clients from server.
     * @return Comma separated String as list of clients
     */
    private String getClients()
    {
	String send = "type:getclients clientid:" + getClientID() + " end:end";
	String mess = sendDataString(send);
	logger.info("sendDataString in getClients() returned = " + mess);

	String para = NeuroNetCom.getParameterArrayFormMessage("clients", mess);

	return para;
    }

    /**
     * This method requests list of clients from server.
     * @return StringVector as list of clients
     */
    public Vector<String> getClientsAsVector()
    {
	String clients = getClients();

	Vector<String> dataVec = NeuroNetCom.getStringAsVector(clients, ",");
	return dataVec;
    }

    public void printClients(Vector<String> dataVec)
    {

	if (dataVec.size() != 0)
	{
	    logger.info("=================== =================== ===================");
	    logger.info("== List of clients online ");
	    // print data
	    int index = 0;
	    for (String client : dataVec)
	    {
		index++;
		logger.info("==  " + index + ") " + client);
	    }
	    logger.info("=================== =================== ===================");
	}
	else
	{
	    logger.info("=================== =================== ===================");
	    logger.info("== Client " + getClientID() + " recieved NO NEW messages ");
	    logger.info("=================== =================== ===================");
	}
    }

    public void printTargets(String requestClient, Vector<String> dataVec)
    {

	if (dataVec.size() != 0)
	{
	    logger.info("=================== =================== ===================");
	    logger.info("== List of targets for client " + requestClient);
	    // print data
	    int index = 0;
	    for (String client : dataVec)
	    {
		index++;
		logger.info("==  " + index + ") " + client);
	    }
	    logger.info("=================== =================== ===================");
	}
	else
	{
	    logger.info("=================== =================== ===================");
	    logger.info("== Client " + requestClient + " has NO registered targets ");
	    logger.info("=================== =================== ===================");
	}
    }

    /**
     * This method requests list of clients from server.
     * @return Comma separated String as list of clients
     */
    public Vector<String> getNewDataAsVector()
    {
	String send = "type:getdata clientid:" + getClientID() + " clientkey:" + getClientKey() + " end:end";
	String mess = sendDataString(send);
	logger.info("sendDataString in getNewDataAsVector() returned = " + mess);

	Vector<String> para = NeuroNetCom.extractDataFromMessage(mess, "data");

	return para;
    }

    public void getData()
    {
	String send = "type:getdata clientid:" + getClientID() + " clientkey:" + getClientKey() + " end:end";
	String mess = sendDataString(send);
	logger.info("sendDataString in getData() returned = " + mess);

	Vector<String> dataVec = NeuroNetCom.extractDataFromMessage(mess);

	// print data
	for (String message : dataVec)
	{
	    // extract data
	    String inTime = NeuroNetCom.getParameterFormMessage("incomingtime", message);
	    String senderID = NeuroNetCom.getParameterFormMessage("senderid", message);
	    String messDataStr = NeuroNetCom.getParameterFormMessage("data", message);

	    logger.info("=================== =================== ===================");
	    logger.info("== Client " + getClientID() + " recieved message from " + senderID);
	    logger.info("==  Data reciedved at " + inTime);
	    logger.info("==  Data content is " + messDataStr);
	    logger.info("=================== =================== ===================");
	}
	if (dataVec.size() == 0)
	{
	    logger.info("=================== =================== ===================");
	    logger.info("== Client " + getClientID() + " recieved NO NEW data ");
	    logger.info("=================== =================== ===================");
	}
    }

    private void resetServer()
    {
	String send = "type:reset end:end";
	String status = sendDataString(send);
	logger.info("resetServer() returned = " + status);
    }

    private void logonClient()
    {
	logonClient(getClientID(), getClientInfo());
    }

    public boolean logonClient(String clientid, String clientinfo)
    {
	// setting new clientID
	clientID = clientid;

	String send = "type:logon clientid:" + clientid + " clientinfo:" + clientinfo + " end:end";
	String status = sendDataString(send);
	logger.info("sendDataString in logonClient() returned = " + status);

	String clientkeyTemp = NeuroNetCom.getParameterFormMessage("clientkey", status);
	if (getClientKey().length() == 0 && !getClientKey().equalsIgnoreCase("-1"))
	{
	    setClientKey(clientkeyTemp);
	    logger.info("ClientKey set to " + getClientKey());
	    setClientID(clientid);
	    return true;
	}
	return false;
	// TODO: Remove
	// do something useful
	//	doSomething();

    }

    public boolean logoffClient()
    {
	String send = "type:logoff clientid:" + getClientID() + " clientkey:" + getClientKey() + " end:end";
	String status = sendDataString(send);
	logger.info("sendDataString in logoffClient() returned = " + status);
	if (!(NeuroNetCom.getParameterFormMessage("clientkey", status).equals("-1")) && NeuroNetCom.getParameterFormMessage("clientkey", status).contains("status:ok"))
	    return true;
	return false;
    }

    public void sendDummyData()
    {
	Random r = new Random();
	String dataString = r.nextInt(10) + ".001,3,12.345,.65545," + r.nextInt();;
	String send = "type:senddata clientid:" + getClientID() + " clientkey:" + getClientKey() + " data[" + dataString + "]" + " end:end";
	String status = sendDataString(send);
	logger.info("sendDataString in sendData() returned = " + status);
    }

    public void configureClient(String dataItems, String targets)
    {
	NeuroNetClient.getGUI().addLogMessage(" Configuring Client ");

	NeuroNetClient.getGUI().addLogMessage(" --" + "");
	String confString = " datatargets[" + targets + "]";
	confString += " dataitems[" + dataItems + "]";
	String send = "type:config clientid:" + getClientID() + " clientkey:" + getClientKey() + confString + " end:end";
	String status = sendDataString(send);
	logger.info("sendDataString ind configureClient() returned = " + status);
    }

    //    private void logoffClientX()
    //    {
    //	try
    //	{
    //	    socket = new Socket(serverURL, serverPort);
    //	}
    //	catch (Exception e)
    //	{
    //	    logger.error("Error connectiong to server:", e);
    //	    return;
    //	}
    //	logger.info("Connection accepted " + socket.getInetAddress() + ":" + socket.getPort());
    //	// Creating data streams
    //	try
    //	{
    //	    inputStream = new ObjectInputStream(socket.getInputStream());
    //	    outputStream = new ObjectOutputStream(socket.getOutputStream());
    //	}
    //	catch (IOException e)
    //	{
    //	    logger.error("Exception creating new Input/output Streams: ", e);
    //	    return;
    //	}
    //
    //	String send = "type:logoff clientid:" + clientid + " clientkey:" + clientkey + " end:end";
    //	// TODO: uncomment 
    //	//	send = "type:logoff clientid:" + clientid + " clientkey:" + clientid + " end:end";
    //
    //	// send the string to the server
    //	logger.info("Client sending \"" + send + "\" to serveur");
    //	try
    //	{
    //	    outputStream.writeObject(send);
    //	    outputStream.flush();
    //	}
    //	catch (IOException e)
    //	{
    //	    logger.error("Error writting to the socket: ", e);
    //	    return;
    //	}
    //
    //	// read server answer
    //	String response;
    //	try
    //	{
    //	    response = (String) inputStream.readObject();
    //	    logger.info("Read from server: " + response);
    //
    //	    String status = NeuroNetCom.getParameterFormMessage("status", response);
    //	    if (status.equalsIgnoreCase("ok"))
    //	    {
    //		logger.info("client sucessfully logged off");
    //	    }
    //	    else
    //	    {
    //		if (status.equalsIgnoreCase("error"))
    //		{
    //		    String errorinfo = NeuroNetCom.getParameterFormMessage("errorinfo", response);
    //		    logger.error("errorinfo " + errorinfo);
    //		}
    //		else
    //		{
    //		    logger.error(" unknown status in serverresponse: " + response);
    //
    //		}
    //	    }
    //	}
    //	catch (Exception e)
    //	{
    //	    logger.error("Problem while reading from server: ", e);
    //	}
    //	// close connections
    //	finally
    //	{
    //	    try
    //	    {
    //		inputStream.close();
    //		outputStream.close();
    //	    }
    //	    catch (Exception e)
    //	    {
    //		logger.error("Problem while closing connection: ", e);
    //	    }
    //	}
    //
    //    }

    public String sendDataString(String send)
    {
	NeuroNetClient.getGUI().addLogMessage(" Sending data ");
	NeuroNetClient.getGUI().addLogMessage(" --" + "" + send);

	String response = "staus:ok";
	if (!GLOBALSOCKET)
	{
	    try
	    {
		socket = new Socket(serverURL, serverPort);
	    }
	    catch (Exception e)
	    {
		logger.error("Error connectiong to server " + serverURL + ":" + serverPort, e);
		NeuroNetClient.getGUI().addLogMessage(" --" + "status:error errorinfo:server_connection_error");
		return "status:error errorinfo:server_connection_error";
	    }
	    NeuroNetClient.getGUI().addLogMessage(" --" + "Connection accepted " + socket.getInetAddress() + ":" + socket.getPort());
	    logger.info("Connection accepted " + socket.getInetAddress() + ":" + socket.getPort());
	}
	// Creating data streams
	try
	{
	    inputStream = new ObjectInputStream(socket.getInputStream());
	    outputStream = new ObjectOutputStream(socket.getOutputStream());
	}
	catch (IOException e)
	{
	    logger.error("Exception creating new Input/output Streams: ", e);
	    NeuroNetClient.getGUI().addLogMessage(" --" + "status:error errorinfo:stream_creation_error");
	    return "status:error errorinfo:stream_creation_error";
	}

	//	String send = "type:logoff clientid:" + clientid + " clientkey:" + clientkey + " end:end";

	// send the string to the server
	logger.info("      ##### Sending:");
	logger.info("Client sending \"" + send + "\" to server");
	NeuroNetClient.getGUI().addLogMessage(" --" + "Sending \"" + send + "\" to server");
	try
	{
	    outputStream.writeObject(send);
	    outputStream.flush();
	}
	catch (IOException e)
	{
	    logger.error("Error writting to the socket: ", e);
	    NeuroNetClient.getGUI().addLogMessage(" --" + "status:error errorinfo:socket_wrte_error");
	    return "status:error errorinfo:socket_wrte_error";
	}

	// read server answer
	try
	{
	    response = (String) inputStream.readObject();
	    logger.info("      ##### Reading:");
	    NeuroNetClient.getGUI().addLogMessage(" --" + "Read from server: \n" + response);
	    logger.info("Read from server: " + response);

	    String status = NeuroNetCom.getParameterFormMessage("status", response);
	    if (status.equalsIgnoreCase("ok"))
	    {
		NeuroNetClient.getGUI().addLogMessage(" --" + "command sucessfully");
		logger.info("command sucessfully");
	    }
	    else
	    {
		if (status.equalsIgnoreCase("error"))
		{
		    String errorinfo = NeuroNetCom.getParameterFormMessage("errorinfo", response);
		    NeuroNetClient.getGUI().addLogMessage(" --" + "errorinfo " + errorinfo);
		    logger.error(" ** errorinfo " + errorinfo);
		}
		else
		{
		    logger.error(" unknown status in serverresponse: " + response);
		    NeuroNetClient.getGUI().addLogMessage(" --" + "status:error errorinfo:unknown_status_error");
		    return "status:error errorinfo:unknown_status_error";
		}
	    }
	}
	catch (Exception e)
	{
	    NeuroNetClient.getGUI().addLogMessage(" --" + "status:error errorinfo:server_read_error");
	    logger.error("Problem while reading from server: ", e);
	    return "status:error errorinfo:server_read_error";
	}
	// close connections
	finally
	{
	    try
	    {
		inputStream.close();
		outputStream.close();
	    }
	    catch (Exception e)
	    {
		NeuroNetClient.getGUI().addLogMessage(" --" + "status:error errorinfo:server_connection_closing_error");
		logger.error("Problem while closing connection: ", e);
		return "status:error errorinfo:server_connection_closing_error";
	    }
	}
	return response;
    }

    //    private void logonClientX()
    //    {
    //	try
    //	{
    //	    socket = new Socket(serverURL, serverPort);
    //	}
    //	catch (Exception e)
    //	{
    //	    logger.error("Error connectiong to server:", e);
    //	    return;
    //	}
    //	logger.info("Connection accepted " + socket.getInetAddress() + ":" + socket.getPort());
    //
    //	// Creating data streams
    //	try
    //	{
    //	    inputStream = new ObjectInputStream(socket.getInputStream());
    //	    outputStream = new ObjectOutputStream(socket.getOutputStream());
    //	}
    //	catch (IOException e)
    //	{
    //	    logger.error("Exception creating new Input/output Streams: ", e);
    //	    return;
    //	}
    //
    //	String send = "type:logon clientid:" + clientid + " clientinfo:" + clientinfo + " end:end";
    //	// send the string to the server
    //	logger.info("Client sending \"" + send + "\" to serveur");
    //	try
    //	{
    //	    outputStream.writeObject(send);
    //	    outputStream.flush();
    //	}
    //	catch (IOException e)
    //	{
    //	    logger.error("Error writting to the socket: ", e);
    //	    return;
    //	}
    //
    //	// read server answer
    //	String response;
    //	try
    //	{
    //	    response = (String) inputStream.readObject();
    //	    logger.info("Read from server: " + response);
    //
    //	    String status = NeuroNetCom.getParameterFormMessage("status", response);
    //	    if (status.equalsIgnoreCase("ok"))
    //	    {
    //		clientkey = NeuroNetCom.getParameterFormMessage("clientkey", response);
    //		logger.info("clientKey set to " + clientkey);
    //		logger.info("client sucessfully logged on");
    //
    //	    }
    //	    else
    //		if (status.equalsIgnoreCase("error"))
    //		{
    //		    String errorinfo = NeuroNetCom.getParameterFormMessage("errorinfo", response);
    //		    logger.error("errorinfo " + errorinfo);
    //		}
    //		else
    //		{
    //		    logger.error(" unknown status in serverrespone: " + response);
    //
    //		}
    //	}
    //	catch (Exception e)
    //	{
    //	    logger.error("Problem while reading from server: ", e);
    //	}
    //	// close connections
    //	finally
    //	{
    //	    try
    //	    {
    //		inputStream.close();
    //		outputStream.close();
    //	    }
    //	    catch (Exception e)
    //	    {
    //		logger.error("Problem while closing connection: ", e);
    //	    }
    //	}
    //
    //    }

    public static void main(String[] arg)
    {

	logger.info("  [[[[[[[[[[[[[[ -=O=- ]]]]]]]]]]]]]]");
	logger.info(" Starting client, checking commandline arguments ...");

	// Set up a simple configuration that logs on the console.
	BasicConfigurator.configure();

	// Check commandline arguments

	//	int serverPortMain = 1504;
	//	String serverURLMain = "localhost";
	// first arg must be the server ip, the second the port
	if (arg.length > 0 && arg[0].length() > 0)
	{
	    try
	    {
		if (arg.length == 2 && arg[0].length() > 0 && arg[1].length() > 0)
		{
		    // get IP
		    String serverURLTemp = arg[0];
		    new URL(serverURLTemp);

		    // get port
		    int serverPortTemp = Integer.valueOf(arg[1]);

		    // No error till now
		    if (serverPortTemp > 0)
			serverPort = serverPortTemp;
		    serverURL = serverURLTemp;
		}
	    }
	    catch (MalformedURLException e)
	    {
		logger.error(" Illegal URL argument!", e);
		e.printStackTrace();
	    }
	    catch (NumberFormatException e)
	    {
		logger.error(" Illegal port argument!", e);
		e.printStackTrace();
	    }
	}

	new NeuroNetClient(serverURL, serverPort, "Client0001");
    }

    public ClientInfo getServerInfoObject()
    {
	NeuroNetClient.getGUI().addLogMessage(" requesting ServerInfo ");
	NeuroNetClient.getGUI().addLogMessage(" --" + " NOT IMPLEMENTED (Just Dummy Data)");

	// TODO: get real server info (implement server side methods!)
	ClientInfo back = new ClientInfo();
	String clientinfo = "Default Server";
	String clientlast = "-1";
	String clientip = serverURL;
	String clientport = "" + serverPort;

	back.setID("Server");
	back.setInfo(clientinfo);
	back.setLast(clientlast);
	back.setIP(clientip);
	back.setPort(clientport);

	return back;
    }

    public ClientInfo getClientInfoObject(String requestclientid)
    {
	NeuroNetClient.getGUI().addLogMessage("Requesting CLientInfo for Client " + requestclientid);

	String send = "type:getinfo clientid:" + getClientID() + " clientkey:" + getClientKey() + " requestclientid:" + requestclientid + " end:end";
	String mess = sendDataString(send);
	logger.info("sendDataString in getClientInfo() returned = " + mess);

	ClientInfo back = new ClientInfo();
	String status = NeuroNetCom.getParameterFormMessage("status", mess);

	if (status.equalsIgnoreCase("OK"))
	{
	    NeuroNetClient.getGUI().addLogMessage(" --" + "status:ok");

	    String clientinfo = NeuroNetCom.getParameterFormMessage("clientinfo", mess);
	    String clientlast = NeuroNetCom.getParameterFormMessage("clientlast", mess);
	    String clientdataitems = NeuroNetCom.getParameterArrayFormMessage("clientdataitems", mess);
	    String clienttargets = NeuroNetCom.getParameterArrayFormMessage("clienttargets", mess);

	    back.setID(requestclientid);
	    back.setInfo(clientinfo);
	    back.setLast(clientlast);
	    back.setDataItems(clientdataitems.split(","));
	    back.setTargets(clienttargets.split(","));

	}
	else
	{
	    NeuroNetClient.getGUI().addLogMessage(" --" + mess);
	}
	return back;
    }

    public String getClientID()
    {
	return clientID;
    }

    public void setClientID(String clientid)
    {
	this.clientID = clientid;
    }

    public String getClientInfo()
    {
	return clientinfo;
    }

    public void setClientInfo(String clientinfo)
    {
	this.clientinfo = clientinfo;
    }

    public String getClientKey()
    {
	return clientkey;
    }

    public void setClientKey(String clientkey)
    {
	this.clientkey = clientkey;
    }

    public static void setGUI(ClientFrame gui)
    {
	NeuroNetClient.gui = gui;
    }

    public static ClientFrame getGUI()
    {
	return gui;
    }

    public void setServer(String serverip, int serverport)
    {
	serverURL = serverip;
	serverPort = serverport;

    }

}
